let request = require("../dx/request");

// request({
//   url: "http://10.10.78.75:40148/api/IntellectDevOps/KnowledgeBase",
//   method: "post",
//   data: {
//     phenomenon: Math.random().toString(32).slice(2),
//     reason: Math.random().toString(32).slice(2),
//     solution: Math.random().toString(32).slice(2),
//     alarmCode: Math.random() * 100 + 1,
//     kbType: "设备&电气知识库",
//   },
// });

function pp(p, r, s) {
  request({
    url: "http://10.10.78.75:40148/api/IntellectDevOps/KnowledgeBase",
    method: "post",
    data: {
      //   phenomenon: Math.random().toString(32).slice(2),
      //   reason: Math.random().toString(32).slice(2),
      //   solution: Math.random().toString(32).slice(2),
      phenomenon: p,
      reason: r,
      solution: s,
      alarmCode: Math.floor(Math.random() * 100 + 60),
      kbType: "设备&电气知识库",
    },
  })
    .then((res) => {
      //   console.log(res);
    })
    .catch((e) => {
      console.log(e);
    });
}

function wait(time) {
  return new Promise((res) => {
    setTimeout(() => {
      res();
    }, time);
  });
}
console.time("start");
async function start() {
  // let a = 0;
  for (let p = 0; p < 100; p++) {
    let pstr = generateRandomChineseString(Math.random() * 5 + 5);
    for (let r = 0; r < 20; r++) {
      let rstr = generateRandomChineseString(Math.random() * 5 + 5);
      for (let s = 0; s < 10; s++) {
        let sstr = generateRandomChineseString(Math.random() * 5 + 5);
        pp(pstr, rstr, sstr);
        await wait(80);
      }
    }
  }
  // while (a < 1000) {
  //   p();
  //   a++;
  //   await wait(100);
  // }
}

start();
console.timeEnd("start");

function generateRandomChineseString(length) {
  var result = "";

  for (var i = 0; i < length; i++) {
    // Unicode编码范围：[\u4e00-\u9fa5]表示汉字的范围
    var randomCode = Math.floor(Math.random() * (0x9fa6 - 0x4e00 + 1) + 0x4e00);

    result += String.fromCharCode(randomCode);
  }

  return result;
}

// 调用函数并输出结果
//console.log(generateRandomChineseString(Math.random() * 5 + 5));
